<template>
  <div class="app-container">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="商品名称">
        <el-input v-model="listQuery.goodsName" />
      </el-form-item>
      <el-form-item label="合作商" v-if="showSupplierNumberList">
        <el-select v-model="listQuery.supplierNumber" placeholder="请选择" clearable>
          <el-option
            v-for="item in supplierNumberList"
            :key="item.shortName"
            :label="item.shortName"
            :value="item.supplierNumber"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getList(1)">搜索</el-button>
        <el-button plain @click="toExport()">excel导出</el-button>
        <el-button plain @click="seeExoprt()">查看导出</el-button>
      </el-form-item>
    </el-form>

    <el-table :inline="true" :data="tableData" border v-loading="listLoading">
      <el-table-column prop="goodsName" label="商品名称"></el-table-column>

      <el-table-column prop="productionFactory" label="厂家"></el-table-column>

      <el-table-column prop="specification" label="规格"></el-table-column>

      <el-table-column prop="approvalNumber" label="批准文号"></el-table-column>

      <el-table-column prop="totalInventory" label="总库存" width="100"></el-table-column>

      <el-table-column prop="LockInventory" label="锁定库存" width="100"></el-table-column>

      <el-table-column prop="saleInventory" label="可销库存" width="100"></el-table-column>

      <el-table-column label="批次号：有效期：库存" width="500">
        <template slot-scope="scope">
          <span v-html="scope.row.batchTermStock"></span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="listQuery.pageNo"
      :limit.sync="listQuery.pageSize"
      @pagination="getList(null)"
    />

    <seeexcels ref="seeexcels" />
  </div>
</template>

<script>
import api from "@/api/report/goodsReport";
import Pagination from "@/components/Pagination";
import seeexcels from "@/components/seeexcel";
import apiPartner from "@/api/partner/partner";
export default {
  name: "supplierStock",
  components: { Pagination, seeexcels },
  data() {
    return {
      listQuery: {
        pageNo: 1,
        pageSize: 10,
        goodsName: "", //商品名称
        supplierNumber: "", //合作商
        shortName: "", //合作商短名
        longName: "" //合作商长名
      },
      showSupplierNumberList:false, //是否显示合作商查询条件
      supplierNumberList: [], //合作商数据集合
      listLoading: true,
      total: 0,
      tableData: []
    };
  },
  created() {
    if(this.$route.query.role == 'admin'){ //合作商
      this.showSupplierNumberList = true
      apiPartner.getSupplierUserForSelect().then(res => {
        this.supplierNumberList = res.data.list;
      });
    }
    
    this.getList();
  },
  methods: {
    getList(pageNo) {
      this.listLoading = true;
      this.listQuery.pageNo = pageNo || this.listQuery.pageNo;  //对分页跳转到第一页的处理
      api.getList(this.listQuery).then(res => {
        let page = res.data.page;
        this.tableData = page.list;
        this.total = page.total;
        this.listLoading = false;
      });
    },
    //导出
    toExport() {
      api.toExport(this.listQuery).then(res => {
        this.$notify({
          title: "导出提示",
          message: res.data.tip,
          type: "success"
        });
      });
    },
    //查看导出
    seeExoprt() {
      this.$refs.seeexcels.open();
    }
  }
  
};
</script>

<style  scoped>
</style>